package nearestValidPoint;

public class Solution {
    public int nearestValidPoint(int x, int y, int[][] points) {
        // 暴力 找到所有的有效点 返回最小的曼哈顿距离
        int minDis = Integer.MAX_VALUE;
        int ans = -1;
        for (int i = 0; i < points.length; i++) {
            if(x == points[i][0]||y == points[i][1]){
                int dis = Math.abs(x-points[i][0]+y-points[i][1]);
                if(minDis>dis){
                    ans = i;
                    minDis = dis;
                }
            }
        }
        return ans;
    }
}
